package com.changgou.user.controller;
import com.changgou.user.pojo.OauthClientToken;
import com.changgou.user.service.OauthClientTokenService;
import com.github.pagehelper.PageInfo;
import entity.Result;
import entity.StatusCode;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/****
 * @Author:shenkunlin
 * @Description:
 * @Date 2019/6/14 0:18
 *****/

@RestController
@RequestMapping("/oauthClientToken")
@CrossOrigin
public class OauthClientTokenController {

    @Autowired
    private OauthClientTokenService oauthClientTokenService;

    /***
     * OauthClientToken分页条件搜索实现
     * @param oauthClientToken
     * @param page
     * @param size
     * @return
     */
    @PostMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@RequestBody(required = false)  OauthClientToken oauthClientToken, @PathVariable  int page, @PathVariable  int size){
        //调用OauthClientTokenService实现分页条件查询OauthClientToken
        PageInfo<OauthClientToken> pageInfo = oauthClientTokenService.findPage(oauthClientToken, page, size);
        return new Result(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * OauthClientToken分页搜索实现
     * @param page:当前页
     * @param size:每页显示多少条
     * @return
     */
    @GetMapping(value = "/search/{page}/{size}" )
    public Result<PageInfo> findPage(@PathVariable  int page, @PathVariable  int size){
        //调用OauthClientTokenService实现分页查询OauthClientToken
        PageInfo<OauthClientToken> pageInfo = oauthClientTokenService.findPage(page, size);
        return new Result<PageInfo>(true,StatusCode.OK,"查询成功",pageInfo);
    }

    /***
     * 多条件搜索品牌数据
     * @param oauthClientToken
     * @return
     */
    @PostMapping(value = "/search" )
    public Result<List<OauthClientToken>> findList(@RequestBody(required = false)  OauthClientToken oauthClientToken){
        //调用OauthClientTokenService实现条件查询OauthClientToken
        List<OauthClientToken> list = oauthClientTokenService.findList(oauthClientToken);
        return new Result<List<OauthClientToken>>(true,StatusCode.OK,"查询成功",list);
    }

    /***
     * 根据ID删除品牌数据
     * @param id
     * @return
     */
    @DeleteMapping(value = "/{id}" )
    public Result delete(@PathVariable String id){
        //调用OauthClientTokenService实现根据主键删除
        oauthClientTokenService.delete(id);
        return new Result(true,StatusCode.OK,"删除成功");
    }

    /***
     * 修改OauthClientToken数据
     * @param oauthClientToken
     * @param id
     * @return
     */
    @PutMapping(value="/{id}")
    public Result update(@RequestBody  OauthClientToken oauthClientToken,@PathVariable String id){
        //设置主键值
        oauthClientToken.setAuthenticationId(id);
        //调用OauthClientTokenService实现修改OauthClientToken
        oauthClientTokenService.update(oauthClientToken);
        return new Result(true,StatusCode.OK,"修改成功");
    }

    /***
     * 新增OauthClientToken数据
     * @param oauthClientToken
     * @return
     */
    @PostMapping
    public Result add(@RequestBody   OauthClientToken oauthClientToken){
        //调用OauthClientTokenService实现添加OauthClientToken
        oauthClientTokenService.add(oauthClientToken);
        return new Result(true,StatusCode.OK,"添加成功");
    }

    /***
     * 根据ID查询OauthClientToken数据
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public Result<OauthClientToken> findById(@PathVariable String id){
        //调用OauthClientTokenService实现根据主键查询OauthClientToken
        OauthClientToken oauthClientToken = oauthClientTokenService.findById(id);
        return new Result<OauthClientToken>(true,StatusCode.OK,"查询成功",oauthClientToken);
    }

    /***
     * 查询OauthClientToken全部数据
     * @return
     */
    @GetMapping
    public Result<List<OauthClientToken>> findAll(){
        //调用OauthClientTokenService实现查询所有OauthClientToken
        List<OauthClientToken> list = oauthClientTokenService.findAll();
        return new Result<List<OauthClientToken>>(true, StatusCode.OK,"查询成功",list) ;
    }
}
